<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>test</title>
        <script type="text/javascript" src="../dist/need.js" ></script>
        <script type='text/javascript' src="../lib/qunit-1.16.0.js" ></script>
        <link rel="stylesheet" href="../lib/qunit-1.16.0.css" />
	</head>
	<body>
		<div id="qunit"></div>
  		<div id="qunit-fixture"></div>
        <div id='output'></div>
        <script type="text/javascript" >
        	
			
			//测试 多次引用模块时 代码是否重复执行 不是多次执行为正确
			//记录模块执行次数
			var runTest1 = 0 , runTest2 = 0 , runTest3 = 0 , runTest4 = 0 , outTest = 0 ;
			
			put('test4',['output','test3'],function(output,test3){
				runTest4 += 1 ;
				return {
					say : function(){
						test3.say();
						output.print('run test4');
					}
				} ;
			});
			
			put('test3',['output','test2'],function(output,test2){
				
				//模块执行次数加1
				runTest3 += 1 ;
				
				var test = {
					say : function( ){
						test2.say();
						output.print('run test3');
					}
				} ;
				
				return test ; 
				
			});
			
			put('test2',['output','test1'],function(output,test1){
				
				//模块执行次数加1
				runTest2 += 1 ;
				
				var test = {
					say : function( ){
						test1.say() ;
						output.print('run test2');
					}
				} ;
				
				return test ;
				
			}) ;
			
			put('test1',['output'],function(output){
				
				//模块执行次数加1
				runTest1 += 1 ;
				
				//测试模块代码
				var test = {
					say : function(){
						output.print('run test1');
					}
				} ;				
				return test ; 
				
			}) ;
			put('output',function(){
				outTest += 1 ;
				return {
					print : function(str){
						var p = document.createElement('p') ;
						p.innerHTML = str ;
						document.getElementById('output').appendChild(p) ;
					}
				} ;
			});
			
			(function(w){
				
				var test1 = need('test1') , test2 = need('test2') , test3 = need('test3') , test4 = need('test4') ;
				
				test4.say();
				
				QUnit.test( '测试 多次引用模块时 代码是否重复执行 不是多次执行为正确' , function( assert ){
					assert.ok( outTest === 1 , "passed" ) ;
					assert.ok( runTest1 === 1 , "passed" ) ;
					assert.ok( runTest2 === 1 , "passed" ) ;
					assert.ok( runTest3 === 1 , "passed" ) ;
					assert.ok( runTest4 === 1 , "passed" ) ;
				} ) ;
				
			}(window));
					
        </script>
    </body>
</html>
